#include <sstream>
#include "AnimationBar.h"

using namespace std;

AnimationBar::AnimationBar(AnimationAlgo * animAlgo) : animAlgo(animAlgo)
{

}

void AnimationBar::Create()
{
    TwCopyCDStringToClientFunc(CopyCDStringToClient);
    //TwCopyStdStringToClientFunc(CopyStdStringToClient);

    m_bar = TwNewBar("BVH Info");
    //m_barConfig = TwNewBar("Deplacement");

    TwDefine(" GLOBAL help='Application using multiple bvh.' "); // Message added to the help bar.

    // Add 'speed' to 'bar': it is a modifable (RW) variable of type TW_TYPE_DOUBLE. Its key shortcuts are [s] and [S].
    /*TwAddVarRW(m_bar, "speed", TW_TYPE_DOUBLE, &animAlgo->speed,
               " label='Speed ratio' min=0.0 max=2.0 step=0.01 keyIncr=s keyDecr=S help='Movement speed (turns/second)' ");*/

    TwAddVarRW(m_bar, "Running", TW_TYPE_BOOLCPP, &animAlgo->running, " key='SPACE' true=Running false=Stoped ");

    /*TwAddButton(m_barConfig, "Left", left, this, "key='LEFT' label='Left' ");
    TwAddButton(m_barConfig, "Right", right, this, "key='RIGHT' label='Right' ");*/
}


AnimationBar::~AnimationBar()
{
   // delete m_bar;
}


void TW_CALL AnimationBar::CopyStdStringToClient(std::string& destinationClientString, const std::string& sourceLibraryString)
{
  // Copy the content of souceString handled by the AntTweakBar library to destinationClientString handled by your application
  destinationClientString = sourceLibraryString;
}

void TW_CALL AnimationBar::CopyCDStringToClient(char **destPtr, const char *src)
{
  size_t srcLen = (src!=NULL) ? strlen(src) : 0;
  size_t destLen = (*destPtr!=NULL) ? strlen(*destPtr) : 0;

  // alloc or realloc dest memory block if needed
  if( *destPtr==NULL )
    *destPtr = (char *)malloc(srcLen+1);
  else if( srcLen>destLen )
    *destPtr = (char *)realloc(*destPtr, srcLen+1);

  // copy src
  if( srcLen>0 )
    strncpy(*destPtr, src, srcLen);
  (*destPtr)[srcLen] = '\0'; // null-terminated string
}
